package com.ruoyi.project.cyq.statistics.service.impl;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.cyq.statistics.domain.IOrderGenre;
import com.ruoyi.project.cyq.statistics.mapper.IOrderGenreMapper;
import com.ruoyi.project.cyq.statistics.service.OrderGenreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 刘鹿
 * @date 2020-09-18 16:06
 */
@Service
public class OrderGenreServiceImpl implements OrderGenreService {

    @Autowired
    private IOrderGenreMapper iOrderGenreMapper;

    //查询数据
    @Override
    public IOrderGenre selectGenreById(long genreId) {
        return iOrderGenreMapper.selectGenreById(genreId);
    }

    //查询数据
    @Override
    public List<IOrderGenre> selectGenreList(IOrderGenre iOrderGenre) {
        return iOrderGenreMapper.selectGenreList(iOrderGenre);
    }

    //检验订单类别名称的唯一性
    @Override
    public String checkGenreNameUnique(IOrderGenre iOrderGenre) {
        long genreId = StringUtils.isNull(iOrderGenre.getGenreId()) ? -1L : iOrderGenre.getGenreId();

        IOrderGenre info = iOrderGenreMapper.checkGenreNameUnique(iOrderGenre.getGenreName());
        if (StringUtils.isNotNull(info) && info.getGenreId() != genreId) {
            return UserConstants.CMS_TYPE_NOT_UNIQUE;
        }
        return UserConstants.CMS_TYPE_UNIQUE;
    }

    //添加订单类别
    @Override
    public int insertOrderGenre(IOrderGenre iOrderGenre) {
        return iOrderGenreMapper.insertOrderGenre(iOrderGenre);
    }

    //修改数据
    @Override
    public int updateOrderGenre(IOrderGenre iOrderGenre) {
        return iOrderGenreMapper.updateOrderGenre(iOrderGenre);
    }

    //删除数据
    @Override
    public int deleteOrderGenreByIds(long[] ids) {
        return iOrderGenreMapper.deleteOrderGenreByIds(ids);
    }
}
